Cold Fusion Cookie Monster
Cold Fusion and Cookies (not so tasty this time, it seems)
I recently came across a problem in a CMS that I write code for where cookies weren't being read properly by the browser. The problem came when a cookie needed to activate the CMS toolbar to turn on the edit capabilities existed in both lower and upper case in the browser but ColdFusion was only updating the upper case one while reading the value of the lower case one as the value used on the cookie{} struct. I didn't find a whole lot on how this was happening but I did eventaully find the answer after some meticulous research and more than a few botched attempts at fixing it.
Cold Fusion Writes Upper Case Cookies
In ColdFusion, anytime the cfcookie tag is used, the cookie is written to the browser in upper case. For example;
gets written to the browser as:
MYCOOKIE:chocolateChip
While the value will be written as provided, the name is always upper-cased. However, there is more than one way to set a cookie, and this is where the problem came in.
Three Ways to Bake a Cookie in Coldfusion
There are three different ways to set a cookie in ColdFusion and, of course, the ability to use dot notation or object notation inside of those methods.
cookie.myCookie = "chocolateChip";
All of the above statements write a cookie to the browser but the
So, What Do I Do About It?
I finally came to the conclusion that the only real consistent way to write a cookie from ColdFusion was to use the
and when the
This allowed me to keep uniformity with how cookies are being set both when using CFML and
As always, I am happy to take comments about this or any other post/page on this site. Shoot me an email if you have something you'd like to point out or add.
posted 11/30/2017 in ColdFusion
Tags: ColdFusion, cookies
Comments:
No comments have been posted.
Leave a comment:
HTML not allowed, max characters 255, * denotes required field.